const mongoose = require("./index");

const UserSchema = new mongoose.Schema(
	{
		// 账号
		username: {
			type: String,
			required: [true, "账号不能为空"],
			unique: [true, "账号已存在"],
		},
		// 密码
		password: {
			type: String,
			required: [true, "密码不能为空"],
			select: false,
		},
		// 昵称
		nickname: {
			type: String,
			required: [true, "昵称不能为空"],
			unique: [true, "昵称已存在"],
		},
		// 手机号
		phone: {
			type: String,
			required: [true, "手机号不能为空"],
		},
		// 头像
		avatar: {
			type: String,
			default: "",
		},
		// 角色
		role: {
			type: [mongoose.SchemaTypes.ObjectId],
			required: [true, "角色不能为空"],
		},
		// 部门
		department: {
			type: String,
			required: [true, "部门不能为空"],
		},
		// 状态
		status: {
			type: String,
			enum: ["disable", "enable"],
			default: "enable",
		},
		// 是否为超级管理员
		isSuper: {
			type: Boolean,
			default: false,
		},
	},
	{ timestamps: true }
);

module.exports = mongoose.model("User", UserSchema);
